package com.ustc.hewei.nettyrpc2_0.common.warp;

import com.ustc.hewei.nettyrpc2_0.common.enumeration.RpcResponseStatus;
import com.ustc.hewei.nettyrpc2_0.common.exception.RpcException;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
* @description: 响应包装类
* @author hewei
* @date 2022/9/5 19:27
* @version 1.0
*/

@Data
@Accessors(chain = true)
public class RpcResponse implements Serializable {
    private String id;

    private Object data;

    private Boolean isSuccess;

    private String exception;

    public static RpcResponse success(RpcRequest request, Object data) {
        RpcResponse response = new RpcResponse();
        response.setId(request.getId()).setData(data).setIsSuccess(true);
        return response;
    }

    public static RpcResponse fail(RpcRequest request, String exception) {
        RpcResponse response = new RpcResponse();
        response.setIsSuccess(false).setId(request.getId()).setException(exception);
        return response;
    }
}
